package com.cy.pj.modules.controller;

import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.common.web.domain.BaseController;
import com.cy.pj.modules.entity.AfStock;
import com.cy.pj.modules.service.IAfStockService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 【请填写功能名称】Controller
 *
 * @author kiven
 * @date 2023-03-19
 */
@Controller
@RequestMapping("/afstock")
public class AfStockController extends BaseController {
    private String prefix = "/modules/afstock";

    @Autowired
    private IAfStockService afStockService;

    @RequiresPermissions("afstock:view")
    @GetMapping()
    public String stock() {
        return prefix + "/afstock";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("afstock:list")
    @GetMapping("/list")
    @ResponseBody
    public JsonResult list(AfStock afStock, Integer pageCurrent) {
        return new JsonResult(afStockService.selectAfStockList(afStock, pageCurrent));
    }

    @GetMapping("/sp")
    @ResponseBody
    public JsonResult sp(Long afStockId) {
        return new JsonResult(afStockService.sp(afStockId));
    }

    //
    ///**
    // * 导出【请填写功能名称】列表
    // */
    //@RequiresPermissions("pj:stock:export")
    //@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    //@PostMapping("/export")
    //@ResponseBody
    //public AjaxResult export(AfStock afStock)
    //{
    //    List<AfStock> list = afStockService.selectAfStockList(afStock);
    //    ExcelUtil<AfStock> util = new ExcelUtil<AfStock>(AfStock.class);
    //    return util.exportExcel(list, "stock");
    //}

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("afstock:add")
    @PostMapping("/add")
    @ResponseBody
    public JsonResult addSave(@Validated AfStock afStock) {
        return new JsonResult(afStockService.insertAfStock(afStock));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        AfStock afStock = afStockService.selectAfStockById(id);
        mmap.put("afStock", afStock);
        return prefix + "/afstock_edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("afstock:update")
    @PostMapping("/edit")
    @ResponseBody
    public JsonResult editSave(AfStock afStock) {
        return new JsonResult(afStockService.updateAfStock(afStock));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("afstock:delete")
    @PostMapping("/remove")
    @ResponseBody
    public JsonResult remove(String ids) {
        return new JsonResult(afStockService.deleteAfStockByIds(ids));
    }
}
